package com.zerui.manager.app.deviceTouchSync.listener;

import com.zerui.manager.app.deviceTouchSync.executer.DeviceTouchSyncQryCmdExe;
import com.zerui.manager.app.deviceTouchSync.executer.DeviceTouchSyncUpdateCmdExe;
import com.zerui.manager.app.scheduler.bean.TaskErrorEvent;
import com.zerui.manager.deviceTouchSync.DeviceTouchSync;
import com.zerui.manager.web.enums.DeviceSyncStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class TaskErrorListener implements ApplicationListener<TaskErrorEvent> {

    @Resource
    private DeviceTouchSyncUpdateCmdExe touchSyncUpdateCmdExe;
    @Resource
    private DeviceTouchSyncQryCmdExe deviceTouchSyncQryCmdExe;

    @Override
    public void onApplicationEvent(TaskErrorEvent event) {
        DeviceTouchSync deviceTouchSync = deviceTouchSyncQryCmdExe.selectById(event.getJobBean().getJobId());
        deviceTouchSync.setSyncStatus(DeviceSyncStatusEnum.SYNC_ERROR.getCode()); // 运行出错
        deviceTouchSync.setSyncRemark(event.getErrorMessage());
        touchSyncUpdateCmdExe.updateSyncInfo(deviceTouchSync);
    }
}
